package org.elec.mac.controller;

import lombok.extern.slf4j.Slf4j;
import org.elec.mac.entity.SOrder;
import org.elec.mac.service.SOrderDetailService;
import org.elec.mac.service.SOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Bean on 2018/4/19.
 */
@Slf4j
@Controller
public class OrderDetailController extends BaseController {

    @Autowired
    private SOrderDetailService sOrderDetailService;

    @Autowired
    private SOrderService sOrderService;

    @RequestMapping(value = "/order_detail.do")
    private String orderListHandler(HttpServletRequest request, HttpServletResponse response, ModelMap model,
                                    @RequestParam(value = "id", required = false) String id) throws IOException {

        Map<String, Object> params = new HashMap<>();
        params.put("oid", id);

        //订单查询
        List<Map<String, Object>> details = sOrderDetailService.orderDetails(params);

        params.clear();
        params.put("id", id);
        SOrder sOrder = sOrderService.get(params);

        model.put("details", details);
        model.put("sOrder", sOrder);
        return "order/order_detail";
    }
}
